/**
  * Copyright 2019 bejson.com 
  */
package com.xingkeduo.dto.transter.order;
import com.xingkeduo.dto.param.OrderParameterDto;
import com.xingkeduo.pojo.enums.RefundType;
import com.xingkeduo.utils.DateTimeUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class Order_list {
    private Boolean is_product;
    private String product_id;
    private String store_name;
    private String status;
    private String status_name;
    private String type;
    private String product_name;
    private int product_nums;
    private String mode;
    private String server_name;
    private String pay_time;
    private String appointment_time;
    private String address;
    private String order_no;
    private String out_order_no;
    private String coupon_price;
    private String discount_price;
    private List<String> pay_price;
    private String market_sell_price;
    private String img_url;
    private boolean can_buy;
    private boolean can_refund;
    private String store_id;
    private String admin_name;
    private Queue queue;


    public void covert(OrderUserResponseDto orderUserResponseDto, Queue queue, boolean can_buy, OrderParameterDto orderParameterDto) {
        this.is_product=false;
        this.product_id=String.valueOf(orderUserResponseDto.getStoreId());
        this.store_name = orderUserResponseDto.getStoreName();

        this.status=String.valueOf(orderUserResponseDto.getStatus().getKey());
        this.status_name=orderUserResponseDto.getStatus().getValue();
        //已完成
        if("SERVICE_DOWN".equals(orderParameterDto.getStatus())){
            this.status="3";
            this.status_name="已完成";
            can_buy=true;
        }
        //待评价
        if("TO_BE_COMMENT".equals(orderParameterDto.getStatus())){
            this.status="2";
            this.status_name="待评价";
        }
        //已退款
        if("REFUND_DONE".equals(orderParameterDto.getStatus())){
            this.status="-2";
            this.status_name="已退款";
        }

        //已退款
        if("PAID".equals(orderParameterDto.getStatus())){
            if("0".equals(this.status)){
                this.status="0";
                this.status_name="待支付";
            }
            if("1".equals(this.status)){
                this.status="1";
                this.status_name="等待中";
            }
            if("5".equals(this.status)){
                this.status="1";
                this.status_name="已过号";
            }
            if("8".equals(this.status)){
                this.status="1";
                this.status_name="等待中";
            }

        }

        //ALL
        if("ALL".equals(orderParameterDto.getStatus())){
            Boolean hadComment = orderUserResponseDto.getHadComment();
            if("-2".equals(this.status)){
                this.status="-2";
                this.status_name="已退款";
            }else if("-1".equals(this.status)){
                if(hadComment){
                    this.status="3";
                    this.status_name="已完成";
                }else{
                    this.status="2";
                    this.status_name="待评价";
                }
            }else if("1".equals(this.status) && hadComment){
                this.status="0";
                this.status_name="等待中";
            }else if("2".equals(this.status)){
                if(hadComment){
                    this.status="3";
                    this.status_name="已完成";
                }else{
                    this.status="0";
                    this.status_name="等待中";
                }
            }else if("3".equals(this.status)){
                if(hadComment){
                    this.status="3";
                    this.status_name="已完成";
                    can_buy=true;
                }else{
                    this.status="2";
                    this.status_name="待评价";
                }
            }else if("5".equals(this.status) && hadComment){
                this.status="1";
                this.status_name="已过号";
            }else if("6".equals(this.status)){
                if(hadComment){
                    this.status="3";
                    this.status_name="已完成";
                }else{
                    this.status="0";
                    this.status_name="等待中";
                }
            }else if("7".equals(this.status)){
                if(hadComment){
                    this.status="3";
                    this.status_name="已完成";
                }else{
                    this.status="0";
                    this.status_name="等待中";
                }
            }else if("8".equals(this.status)){
                this.status="0";
                this.status_name="等待中";
            }else if("9".equals(this.status)){
                if(hadComment){
                    this.status="3";
                    this.status_name="已完成";
                }else{
                    this.status="0";
                    this.status_name="等待中";
                }
            }
        }

        try {
            this.type = String.valueOf(orderUserResponseDto.getPayType().getKey());
        } catch (Exception e) {
            e.printStackTrace();
        }

        this.product_name = DateTimeUtils.yyyyMMdd_HH_mm_ss(orderUserResponseDto.getAppointmentStartTime());
        this.product_nums=1;
        this.mode="2";
        this.server_name = orderUserResponseDto.getServiceTypeName();
        this.pay_time =  orderUserResponseDto.getPayTime()==null?null:DateTimeUtils.yyyy_MM_dd_HH_mm_ss(orderUserResponseDto.getPayTime()).replaceAll("-",".");
        this.appointment_time =  DateTimeUtils.yyyy_MM_dd_HH_mm_ss(orderUserResponseDto.getAppointmentStartTime()).replaceAll("-",".");
        this.address = orderUserResponseDto.getStoreAddress();
        this.order_no = orderUserResponseDto.getOrderNo();
        this.out_order_no = orderUserResponseDto.getOutOrderNo();
        this.coupon_price=String.valueOf(orderUserResponseDto.getMarketingPrice());
        if(orderUserResponseDto.getAllPrice()!=null && orderUserResponseDto.getPayPrice()!=null){
            this.discount_price = String.valueOf(orderUserResponseDto.getCouponPrice());
        }
        List<String> list = new ArrayList<>();
        String allPrice = String.valueOf(orderUserResponseDto.getPayPrice());
        int num = allPrice.indexOf(".");
        list.add( allPrice.indexOf(".")>0?allPrice.substring(0,num):allPrice);
        list.add( allPrice.indexOf(".")>0?allPrice.substring(num+1,allPrice.length()):"00");
        this.pay_price = list;
        this.market_sell_price = allPrice;
        this.img_url = "预约发型师头像";
        this.can_buy = can_buy;
        this.can_refund = orderUserResponseDto.checkRefund(RefundType.USER);
        this.store_id  = String.valueOf(orderUserResponseDto.getStoreId());
        this.admin_name = orderUserResponseDto.getAdminNickName();
        this.queue = queue;

    }

}